package com.frxuexi.shop.viewmodel

import com.frxuexi.lib_base.http.ShopApiService
import com.frxuexi.lib_base.mvi.BaseViewModel
import com.frxuexi.lib_base.mvi.RequestType
import com.frxuexi.lib_base.room.OrderDao
import com.frxuexi.shop.intent.OrderIntent
import dagger.hilt.android.lifecycle.HiltViewModel
import kotlinx.coroutines.flow.flow
import javax.inject.Inject

@HiltViewModel
class OrderViewModel @Inject constructor(val orderDao: OrderDao):BaseViewModel<OrderIntent>(){
    override fun handleIntent(it: OrderIntent) {
        when(it){
            is OrderIntent.getAllOrders->roomRequest(flow { emit(orderDao.getAllOrders()) })
            is OrderIntent.updateOrder->roomRequest(flow { emit(orderDao.updateOrder(it.orderEntity)) },RequestType.UPDATE)
            is OrderIntent.getOrderByStatus->roomRequest(flow { emit(orderDao.getOrderByStatus(it.status)) })
            is OrderIntent.deleteOrder->roomRequest(flow { emit(orderDao.deleteOrder(it.orderEntity)) },RequestType.UPDATE)
        }
    }
}